
#include <stdio.h>
#include "websocket.h"
#include "handle_protcol.h"
#include <pthread.h>


int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                          void *(*start_routine) (void *), void *arg);

void *pthread_func(void * arg){

	init_websocket_v12();
}



int main(int argc, char const *argv[])
{
	
	
	pthread_t id;
	pthread_create(&id,NULL,pthread_func,NULL);

	while(1){
		test_pro();
	}
	// protocol *tmp = create_pro();
	// putData(tmp,WX_APP,WX_APP_T,0,1,0xff);
	// test(tmp);
	// host2net(tmp);
	// test(tmp);

	// protocol *tmp_get = create_pro();
	// getData(tmp_get,(char *)tmp);
	// test(tmp_get);

	// free_pro(tmp);
	// free_pro(tmp_get);
	return 0;
}

int test_pro(){
	printf("============================================\n \
			1. 温度测试\n \
			2. 湿度测试\n \
			3. 光照测试\n \
			4. MQ_2测试\n \
			5. 字符串测试\n \
			6. 单字符测序\n\
			7. 状态测试（二进制）\n");
	printf("============================================\n");
	fflush(stdin);
	int tmp = 0;
	scanf("%d",&tmp);
	// printf("%d,%c\n",tmp,tmp);
	protocol *tmp_pro = create_pro();
	switch(tmp){
		case 1 :{
			putData(tmp_pro,WX_APP,WX_APP_T,0,0,40);
			break;
		}
		case 2 :{
			putData(tmp_pro,WX_APP,WX_APP_H,0,0,50);
			break;
		}
		case 3:{
			putData(tmp_pro,WX_APP,WX_APP_L,0,0,60);
			break;
		}
		case 4:{
			putData(tmp_pro,WX_APP,WX_APP_MQ_2,0,0,0xff);
			break;
		}
		case 5:{
			// putData(tmp_pro,WX_APP,WX_APP_FUNC_STATUS,0,0,0xff);
			websocket_send("abcdefyq",8);
			return 0;
			break;
		}
		case 6:{
			websocket_send("A",1);
			return 0;
			break;
		}
		case 7:{
			putData(tmp_pro,WX_APP,WX_APP_FUNC_STATUS,0,0,LCD_OK|TEM_OK|H_OK|L_OK);
			break;
		}
		default:{
			printf("cmd error!\n");
			return -1;
		}
	}

	printf("0x%8x,0x%8x\n", *(unsigned int *)tmp_pro,*((unsigned int *)tmp_pro+1));
	host2net(tmp_pro);
	websocket_send(tmp_pro,8);
	free_pro(tmp_pro);
	return 0;

}